<template>
	<div class="place_order_entity">
		<top-user-info style="margin-bottom: 20px;"/>
		<bottom-goods-info ref="bgi" @inloading="outloading"  />
		<van-submit-bar
			:price="newtotal"
			label="总计："
			buttonText="提交订单"
			:loading="isSubmit"
			:disabled="isDisabled"
			@submit="onSubmit"
			style="bottom: 0;"
		/>
		<form id="payform" :action="payurl" method="post" :onsubmit="doSubmitCheck" @submit.prevent="foo">
			<input v-model="addressId" type="hidden"  >
			<input v-model="paytype" type="hidden" >
		    <input v-model="orders" type="hidden" >
		    
		</form>
		
	</div>
</template>

<script>
	import topUserInfo from "./top-user-info";
	import bottomGoodsInfo from './bottom-goods-info';

	export default {
		
		data(){
			return {
				addressId:0,
				paytype:1,
				orders:[],
				payurl:process.env.API_ROOT + '/order/create',
				isSubmit: false,
				isDisabled: false,
				newtotal:0
			}
		},
		
		methods:{
			doSubmitCheck: function(){
				var chosenContactId=localStorage["chosenContactId"];
				this.addressId = chosenContactId;
				var goodsnew=localStorage["goodsnew"];
				this.orders = goodsnew;
				var paytype=localStorage["paytype"];
				this.paytype = paytype;
                if (this.addressId == 0) {
                	Toast.fail('未选择收获地址');
                    return false;
                } 
                if(!(this.paytype == 1 || this.paytype == 2)){
                	Toast.fail('支付方式不正确');
                    return false;
                }
                if (this.orders.lenght == 0) {
                	Toast.fail('订单为空');
                    return false;
                } 
                return true;
            },
			outloading(v){
				this.newtotal=v;
			},
			onSubmit(){
				this.isSubmit = true;
				document.getElementById('payform').onsubmit();

			}
		},
		
		components: {
			//[SubmitBar.name]: SubmitBar,
			[topUserInfo.name]: topUserInfo,
			[bottomGoodsInfo.name]: bottomGoodsInfo,
		}
	}
</script>


<style lang="scss" scoped>
	
	.place_order_entity{
		padding-bottom: 70px;
	}
</style>